<template>
  <div class="full_Return_Details_list">
    <c-title :hide="false" :text="$route.query.name"></c-title>
    <div class="list">
      <div class="title">活动商品</div>
      <div class="lis" v-for="item in dataList" :key="item.id" @click="tolink(item, 'goods', { id: item.id })">
        <img :src="item.thumb" class="lis_img" alt="" />
        <div class="lis_r">
          <div class="lis_r_name van-ellipsis">{{ item.title }}</div>
          <div class="lis_r_price">{{ $i18n.t("money") }}{{ item.price }}</div>
        </div>
        <i class="iconfont icon-icon_more11"></i>
      </div>
    </div>
  </div>
</template>
<script>
import { scrollMixin } from "utils/mixin";
export default {
  mixins: [scrollMixin],
  data() {
    return {
      page: 1,
      total_page: 0,
      isLoadMore: true,
      dataList: []
    };
  },
  activated() {
    if (this.$route.query.name) {
      this.fun.setWXTitle(this.$route.query.name);
    }
    this.init();
    this.getData();
  },
  methods: {
    tolink(item, key, params = {}) {
      this.$router.push(this.fun.getUrl(key, params));
    },
    init() {
      this.page = 1;
      this.total_page = 0;
      this.isLoadMore = true;
      this.dataList = [];
    },
    async getData() {
      let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.activity.goodsList", { id: this.$route.params.id }, "");
      if (result) {
        this.dataList = data.data;
        this.total_page = data.last_page;
        this.isLoadMore = true;
      } else {
        this.$toast(msg);
      }
    },
    async getMoreData() {
      if (!this.isLoadMore) return;
      this.isLoadMore = false; // 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page += 1;
        let json = {
          page: this.page,
          id: this.$route.params.id
        };
        let { data, msg, result } = await $http.post("plugin.cloud-shop.frontend.activity.goodsList", json, "");
        this.isLoadMore = true;
        if (result) {
          this.dataList = this.dataList.concat(data.data);
        } else {
          this.page = this.page - 1;
          this.$toast(msg);
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.full_Return_Details_list {
  min-height: 100vh;
  width: 100%;
  overflow: hidden;
  background: #faba4d;
  .list {
    margin: 0.63rem 0.75rem;
    border-radius: 0.5rem 0.5rem 0.5rem 0.5rem;
    background: #ffffff;
    padding: 0.94rem 0.63rem;
    box-sizing: border-box;
    .title {
      font-weight: bold;
      font-size: 0.94rem;
      color: #00001c;
      text-align: left;
      margin-bottom: 0.88rem;
    }
    .lis {
      padding: 0.31rem;
      box-sizing: border-box;
      background: #f5f5f5;
      border-radius: 0.63rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      margin-bottom: 0.63rem;
      .lis_img {
        flex-shrink: 0;
        width: 3.63rem;
        height: 3.63rem;
        background: #f0f0f1;
        border-radius: 0.5rem;
        margin: 0;
        margin-right: 0.94rem;
      }
      .lis_r {
        flex: 1;
        display: flex;
        flex-direction: column;
        text-align: left;
        overflow: hidden;
        .lis_r_name {
          font-weight: 500;
          font-size: 0.88rem;
          line-height: 1rem;
          color: #00001c;
          margin-bottom: 0.5rem;
        }
        .lis_r_price {
          font-weight: 500;
          font-size: 0.94rem;
          color: #f15353;
        }
      }
      .icon-icon_more11 {
        flex-shrink: 0;
        color: #aaaab3;
      }
    }
    .lis:last-child {
      margin-bottom: 0;
    }
  }
}
</style>
